package com.quanyan.platform.web;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.quanyan.api.APIResponse;
import com.quanyan.api.enums.ApiResponseEnum;
import com.quanyan.place.entity.PlaceDubboProvider;
import com.quanyan.platform.service.IplaceService;

/**
 * Created by jingliu on 17/3/10.
 */
@RestController
@RequestMapping("/api/platform/place")
public class APIPlacePlatformController {
	private static final Logger logger = LoggerFactory.getLogger(APIPlacePlatformController.class);

	@Autowired
	IplaceService iplaceService;

	/**
	 * 获取我的场馆信息列表
	 *
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "/myPlace")
	public APIResponse<Map<String, List<PlaceDubboProvider>>> myPlace(@RequestBody @Valid Map<String, Object> map,
	                                                                  BindingResult bindingResult,
	                                                                  HttpServletRequest request) {
		if (bindingResult.hasErrors()) {
			return APIResponse.returnFail(ApiResponseEnum.PARAMETER_INVALID);
		}
		if (null == request.getAttribute("uid") || 0 == (Integer) request.getAttribute("uid")) {
			return APIResponse.returnFail(ApiResponseEnum.NEED_USER_LOGIN);
		}
		Integer uid = (Integer) request.getAttribute("uid");
		Double lat = MapUtils.getDouble(map, "lat", 0D);
		Double lng = MapUtils.getDouble(map, "lng", 0D);
		return iplaceService.getMyPlaces(uid, lat, lng);
	}
}
